from enum import Enum
from fastapi import FastAPI


class ModelName(str, Enum):
    alexnet = "alexnet"
    resnet = "resnet"
    lenet = "lenet"


app = FastAPI()


@app.get("/models/{model_name}")
async def get_model(model_name: ModelName):
    '''
    async def
    表示定义一个异步函数（coroutine function）
    当调用这个函数时，会返回一个协程对象（coroutine object），而不是立即执行函数体
    需要配合 await 关键字或事件循环来执行
    '''
    if model_name is ModelName.alexnet:
        return {"model_name": model_name, "message": " if model_name is ModelName.alexnet: "}
    if model_name.value == "lenet":
        return {"model_name": model_name, "message": " if model_name.value == 'lenet'"}
    return {"model_name": model_name, "message": "esle "}


if __name__ == '__main__':
    import uvicorn

    # uvicorn.run(app, host='127.0.0.1', port=8000, log_level='debug')
    uvicorn.run(app, host='127.0.0.1', port=8000)
